/**
 * @author Luc Yriarte
 * 
 * Licence : BSD http://www.opensource.org/licenses/bsd-license.php
 *  
 */

package basicSim;

public class Grid extends Object3D {

	/**
	 * Grid on the XY plane, n steps of one unit.
	 */

	public static int DRAW_DEFAULT = DRAW_WIREFRAME;
	
	double unit;
	int steps;

	public Grid(double u, int n) {
		super();
		int i;
		unit = u;
		steps = n;
		Vector3D[] v = new Vector3D[n * 4 + 1];
		int[][] e = new int[n * 2 + 2][2];
		for (i = 0; i < n; i++) {
			v[i] = new Vector3D(i * unit, 0, 0);
			v[i + n] = new Vector3D(i * unit, 0, n * unit);
			e[i][0] = i;
			e[i][1] = i + n;
			v[i + 2 * n] = new Vector3D(0, 0, i * unit);
			v[i + 3 * n] = new Vector3D(n * unit, 0, i * unit);
			e[i + n][0] = i + 2 * n;
			e[i + n][1] = i + 3 * n;
		}
		v[n * 4] = new Vector3D(n * unit, 0, n * unit);
		e[2 * n][0] = 3 * n;
		e[2 * n][1] = 4 * n;
		e[2 * n + 1][0] = n;
		e[2 * n + 1][1] = 4 * n;
		mesh = new Mesh(n * 4 + 1, n * 2 + 2, v, e);
	}

	public String strObject(int nTab) {
		String str = "", strTab = "";
		for (int i = 0; i < nTab; i++)
			strTab += "\t";
		str += strTab + "{ grid n=" + new Integer(steps).toString() 
				+ " u=" + new Double(unit).toString() + "\n";
		str += strCoord(nTab);
		str += strColor(nTab);
		str += strChild(nTab);
		str += strTab + "}\n";
		return str;
	}

}
